package com.xmall.controller.admin;


import com.xmall.bean.vo.BaseRespVo;
import com.xmall.bean.table.Category;
import com.xmall.bean.vo.CategoryLevelVO;
import com.xmall.bean.vo.CategoryVO;
import com.xmall.service.MallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("admin/category")
public class CategoryController {
    @Autowired
    MallService mallService;

    @RequestMapping("list")
    public BaseRespVo showList(){
        List<CategoryVO> categoryVOList = mallService.showList();
        return BaseRespVo.ok(categoryVOList);
    }

    @RequestMapping("l1")
    public BaseRespVo showListLevelOne(){
        List<CategoryLevelVO> categoryLevelVOS = mallService.showListLevelOne();
        return BaseRespVo.ok(categoryLevelVOS);
    }

    @RequestMapping("create")
    public BaseRespVo AddCategory(@RequestBody Category category){
        Category categoryVO = mallService.updateCategory(category);
        return BaseRespVo.ok(categoryVO);
    }

    @RequestMapping("update")
    //商场管理-商品类目编辑
    public BaseRespVo updateCategoryInMall(@RequestBody CategoryVO categoryVO){
        Integer i= mallService.updateCategoryInMall(categoryVO);
        if(i == 401){
            return BaseRespVo.fail("参数不对");
        }
        return BaseRespVo.ok();
    }

    @RequestMapping("delete")
    public BaseRespVo deleteCategoryInMall(@RequestBody CategoryVO categoryVO){
        mallService.deleteCategoryByLogical(categoryVO);
        return BaseRespVo.ok("成功");
    }


}
